home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / misc / emu / amiSPIMsrc.lha / cl-cycle.h < prev    next >
C/C++ Source or Header  |  1992-11-06  |  10KB  |  315 lines

  1. /* SPIM S20 MIPS Cycle Level simulator.
  2.    Definitions for the SPIM S20 Cycle Level Simulator (SPIM-CL).
  3.    Copyright (C) 1991-1992 by Anne Rogers (amr@cs.princeton.edu) and
  4.    Scott Rosenberg (scottr@cs.princeton.edu)
  5.    ALL RIGHTS RESERVED.
  6.  
  7.    SPIM-CL is distributed under the following conditions:
  8.  
  9.      You may make copies of SPIM-CL for your own use and modify those copies.
  10.  
  11.      All copies of SPIM-CL must retain our names and copyright notice.
  12.  
  13.      You may not sell SPIM-CL or distributed SPIM-CL in conjunction with a
  14.      commerical product or service without the expressed written consent of
  15.      Anne Rogers.
  16.  
  17.    THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  18.    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  19.    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20.    PURPOSE.
  21. */
  22.  
  23. #define FALSE 0
  24. #define TRUE 1
  25.  
  26. #define set_ex_bypass(r, val)   \
  27. { EX_bp_reg = r;                \
  28.   EX_bp_val = val;              \
  29. }
  30.  
  31. #define set_mem_bypass(r, val)  \
  32. { MEM_bp_reg = r;               \
  33.   MEM_bp_val = val;             \
  34. }
  35.  
  36. #define read_R_reg(r)                                       \
  37.   (((r) == 0)                                               \
  38.       ? 0                                                   \
  39.       : ((EX_bp_reg == (r))                                       \
  40.          ? EX_bp_val                                             \
  41.          : ((MEM_bp_reg == (r)) ? MEM_bp_val :  R[(r)])))
  42.  
  43. /* cc = 1 => CPR register, cc = 0 => CCR register  */
  44. #define set_CP_bypass(z, r, value, cc)          \
  45. {  CP_bp_reg = r;                               \
  46.    CP_bp_val = value;                           \
  47.    CP_bp_cc = cc;                               \
  48.    CP_bp_z = z;                                 \
  49.    }
  50.  
  51.  
  52. /* cc = 1 => CPR register, cc = 0 => CCR register  */
  53. #define read_CP_reg(z, r, cc)                                    \
  54.   (((z == CP_bp_z) && (CP_bp_reg == (r))  && (cc == CP_bp_cc))   \
  55.    ? CP_bp_val                                                   \
  56.    : ((cc == 1) ? CPR[z][r] : CCR[z][r]))
  57.  
  58. #define bp_clear()                        \
  59. { EX_bp_reg = 0;                          \
  60.   MEM_bp_reg = 0;                         \
  61.   CP_bp_reg = 0;                          \
  62. }
  63.  
  64.  
  65. #define SIGN_BIT(X) ((X) & 0x80000000)
  66.  
  67. #define ARITH_OVFL(RESULT, OP1, OP2) (SIGN_BIT (OP1) == SIGN_BIT (OP2) \
  68.                       && SIGN_BIT (OP1) != SIGN_BIT (RESULT))
  69.  
  70.  
  71. struct pipe_stage {
  72.   instruction *inst;
  73.   int stage;
  74.   mem_addr pc;
  75.   reg_word op1, op2, op3;
  76.   reg_word value;
  77.   reg_word value1;
  78.   double fop1, fop2;
  79.   double fval;
  80.   reg_word addr_value;
  81.   mem_addr paddr;
  82.   unsigned int req_num;
  83.   int dslot;
  84.   int exception;
  85.   int cyl_count;
  86.   int count;
  87.   struct pipe_stage *next;
  88. };
  89.  
  90. typedef struct pipe_stage *PIPE_STAGE;
  91.  
  92.  
  93. #define VALUE(ps) (ps->value)
  94. #define VALUE1(ps) (ps->value1)
  95. #define ADDR(ps) (ps->addr_value)
  96. #define PADDR(ps) (ps->paddr)
  97. #define RNUM(ps) (ps->req_num)
  98. #define STAGE(ps) (ps->stage)
  99. #define Operand1(ps) (ps->op1)
  100. #define Operand2(ps) (ps->op2)
  101. #define Operand3(ps) (ps->op3)
  102. #define FPoperand1(ps) (ps->fop1)
  103. #define FPoperand2(ps) (ps->fop2)
  104. #define FPvalue(ps) (ps->fval)
  105. #define STAGE_PC(ps) (ps->pc)
  106. #define DSLOT(ps) (ps->dslot)
  107. #define EXCPT(ps) (ps->exception)
  108. #define CYL_COUNT(ps) (ps->cyl_count)
  109. #define Count(ps) (ps->count)
  110.  
  111.  
  112.  
  113. /* CU0 at bit 28, CU2 at bit 30, CU3 at bit 31 */
  114. #define COP_Available(cp)     ((Status_Reg >> (28 + cp)) & 0x1)
  115.  
  116. #define IS_BRANCH(oc) \
  117.    ((oc ==  Y_BC0F_OP)  || (oc == Y_BC2F_OP) || \
  118.     (oc == Y_BC3F_OP)   || (oc == Y_BC0T_OP) || \
  119.     (oc == Y_BC2T_OP)   || (oc == Y_BC3T_OP) || \
  120.     (oc == Y_BEQ_OP)    || (oc == Y_BGEZ_OP) || \
  121.     (oc == Y_BGEZAL_OP) || (oc == Y_BGTZ_OP) || \
  122.     (oc == Y_BLEZ_OP)   || (oc == Y_BLTZ_OP) || \
  123.     (oc == Y_BLTZAL_OP) || (oc == Y_BNE_OP)  || \
  124.     (oc == Y_J_OP)      || (oc == Y_JAL_OP)  || \
  125.     (oc == Y_JALR_OP)   || (oc == Y_JR_OP))
  126.  
  127. #define IS_MEM_OP(oc)                                              \
  128.    ((oc == Y_LB_OP)   || (oc == Y_LBU_OP)  || (oc == Y_LH_OP)   || \
  129.     (oc == Y_LHU_OP)  || (oc == Y_LW_OP)   || (oc == Y_LWL_OP)  || \
  130.     (oc == Y_LWR_OP)  || \
  131.     (oc == Y_LWC0_OP) || (oc == Y_LWC3_OP) || (oc == Y_LWC1_OP) || \
  132.     (oc == Y_SB_OP)   || (oc == Y_SH_OP)   || (oc == Y_SWC1_OP) || \
  133.     (oc == Y_SW_OP)   || (oc == Y_SWC0_OP) ||                      \
  134.     (oc == Y_SWC3_OP) || (oc == Y_SWL_OP)  || (oc == Y_SWR_OP)  || \
  135.     (oc == Y_LWC2_OP) || (oc == Y_SWC2_OP))
  136.  
  137. #define IS_LOAD_OP(oc)                                              \
  138.    ((oc == Y_LB_OP)   || (oc == Y_LBU_OP)  || (oc == Y_LH_OP)   || \
  139.     (oc == Y_LHU_OP)  || (oc == Y_LW_OP)   || (oc == Y_LWL_OP)  || \
  140.     (oc == Y_LWR_OP)  || (oc == Y_LWC0_OP) || (oc == Y_LWC3_OP) || \
  141.     (oc == Y_LWC1_OP) || (oc == Y_LWC2_OP))
  142.  
  143. #define IS_STORE_OP(oc)                                             \
  144.     ((oc == Y_SB_OP)   || (oc == Y_SH_OP)   || (oc == Y_SWC1_OP) || \
  145.      (oc == Y_SW_OP)   || (oc == Y_SWC0_OP) ||                      \
  146.      (oc == Y_SWC3_OP) || (oc == Y_SWL_OP)  || (oc == Y_SWR_OP)  || \
  147.      (oc == Y_SWC2_OP))
  148.  
  149.  
  150.  
  151. #define FPA_FWB 5
  152. #define FPA_EX3 4
  153. #define FPA_EX2 3
  154. #define FPA_EX1 2
  155. #define WB 4
  156. #define MEM 3
  157. #define EX 2
  158. #define ID 1
  159. #define IF 0
  160. #define DONE 0
  161. #define IF_STALL -1
  162. #define MEM_STALL -2
  163. #define STALL -3
  164.  
  165. #define ALU 0
  166. #define FPA 1
  167.  
  168. #define PRINT_INT_SYSCALL    1
  169. #define PRINT_FLOAT_SYSCALL    2
  170. #define PRINT_DOUBLE_SYSCALL    3
  171. #define PRINT_STRING_SYSCALL    4
  172. #define READ_INT_SYSCALL    5
  173. #define READ_FLOAT_SYSCALL    6
  174. #define READ_DOUBLE_SYSCALL    7
  175. #define READ_STRING_SYSCALL    8
  176. #define SBRK_SYSCALL        9
  177. #define EXIT_SYSCALL        10
  178.  
  179.  
  180.  
  181. struct mult_div_unit {
  182.   int count;
  183.   reg_word hi_val;
  184.   reg_word lo_val;
  185. };
  186.  
  187.  
  188. #define MULT_COST 12
  189. #define DIV_COST 33
  190.  
  191. /* floating point stuff */
  192.  
  193. /* Both fr and fr+1 must be set to 1 */
  194. #define is_present(fr) (((FP_reg_present >> (fr)) & 0x1) &&            \
  195.             ((FP_reg_present >> (fr+1)) & 0x1))
  196.  
  197. #define is_single_present(fr) ((FP_reg_present >> (fr)) & 0x1)
  198.  
  199. #define set_present(fr)                                  \
  200. { FP_reg_present = FP_reg_present | (1 << fr) | (1 << (fr+1));          \
  201.   }
  202.  
  203. #define set_single_present(fr)                                        \
  204. { FP_reg_present = FP_reg_present | (1 << (fr));                        \
  205.   }
  206.  
  207. #define clr_present(fr)                                 \
  208. { FP_reg_present = FP_reg_present & (0xffffffff ^ (0x3 << fr));  \
  209.   }
  210.  
  211. #define clr_single_present(fr)                                 \
  212. { FP_reg_present = FP_reg_present & (0xffffffff ^ (0x1 << (fr)));  \
  213.   }
  214.  
  215. /* doesn't include BC1F, BC1T, MTC1, MFC1, or LWC1 which are mostly ALU operations */
  216. #define is_fp_op(oc)                      \
  217.   ((oc == Y_ABS_S_OP) ||                   \
  218.    (oc == Y_ABS_D_OP) ||                   \
  219.    (oc == Y_ADD_S_OP) ||                   \
  220.    (oc == Y_ADD_D_OP) ||                   \
  221.    (oc == Y_C_F_S_OP) ||                   \
  222.    (oc == Y_C_UN_S_OP) ||                   \
  223.    (oc == Y_C_EQ_S_OP) ||                   \
  224.    (oc == Y_C_UEQ_S_OP) ||                   \
  225.    (oc == Y_C_OLE_S_OP) ||                   \
  226.    (oc == Y_C_ULE_S_OP) ||                   \
  227.    (oc == Y_C_SF_S_OP) ||                   \
  228.    (oc == Y_C_NGLE_S_OP) ||                   \
  229.    (oc == Y_C_SEQ_S_OP) ||                   \
  230.    (oc == Y_C_NGL_S_OP) ||                   \
  231.    (oc == Y_C_LT_S_OP) ||                   \
  232.    (oc == Y_C_NGE_S_OP) ||                   \
  233.    (oc == Y_C_LE_S_OP) ||                   \
  234.    (oc == Y_C_NGT_S_OP) ||                   \
  235.    (oc == Y_C_F_D_OP) ||                   \
  236.    (oc == Y_C_UN_D_OP) ||                   \
  237.    (oc == Y_C_EQ_D_OP) ||                   \
  238.    (oc == Y_C_UEQ_D_OP) ||                   \
  239.    (oc == Y_C_OLE_D_OP) ||                   \
  240.    (oc == Y_C_ULE_D_OP) ||                   \
  241.    (oc == Y_C_SF_D_OP) ||                   \
  242.    (oc == Y_C_NGLE_D_OP) ||                   \
  243.    (oc == Y_C_SEQ_D_OP) ||                   \
  244.    (oc == Y_C_NGL_D_OP) ||                   \
  245.    (oc == Y_C_LT_D_OP) ||                   \
  246.    (oc == Y_C_NGE_D_OP) ||                   \
  247.    (oc == Y_C_LE_D_OP) ||                   \
  248.    (oc == Y_C_NGT_D_OP) ||                   \
  249.    (oc == Y_CFC1_OP) ||                   \
  250.    (oc == Y_CTC1_OP) ||                   \
  251.    (oc == Y_CVT_D_S_OP) ||                   \
  252.    (oc == Y_CVT_D_W_OP) ||                   \
  253.    (oc == Y_CVT_S_D_OP) ||                   \
  254.    (oc == Y_CVT_S_W_OP) ||                   \
  255.    (oc == Y_CVT_W_D_OP) ||                   \
  256.    (oc == Y_CVT_W_S_OP) ||                   \
  257.    (oc == Y_DIV_S_OP) ||                   \
  258.    (oc == Y_DIV_D_OP) ||                   \
  259.    (oc == Y_MOV_S_OP) ||                   \
  260.    (oc == Y_MOV_D_OP) ||                   \
  261.    (oc == Y_MUL_S_OP) ||                   \
  262.    (oc == Y_MUL_D_OP) ||                   \
  263.    (oc == Y_NEG_S_OP) ||                   \
  264.    (oc == Y_NEG_D_OP) ||                   \
  265.    (oc == Y_SUB_S_OP) ||                   \
  266.    (oc == Y_SUB_D_OP))
  267.  
  268.  
  269. #define is_store(oc)                      \
  270.   ((oc == Y_SW_OP) ||                     \
  271.    (oc == Y_SWL_OP) ||                    \
  272.    (oc == Y_SWR_OP) ||                    \
  273.    (oc == Y_SWC0_OP) ||                   \
  274.    (oc == Y_SWC1_OP) ||                   \
  275.    (oc == Y_SWC2_OP) ||                   \
  276.    (oc == Y_SWC3_OP) ||                   \
  277.    (oc == Y_SB_OP) ||                     \
  278.    (oc == Y_SH_OP))
  279.  
  280.  
  281. /* not currently in use; cycle spim never leaps to kernel code */
  282. #define SHIFT_Status()                            \
  283.   Status_Reg = (Status_Reg & 0xffffffc0) | ((Status_Reg & 0xf) << 2)
  284. #define RESTORE_Status()                         \
  285.   Status_Reg = (Status_Reg & 0xffffffc0) | ((Status_Reg & 0x3c) >> 2)
  286.  
  287.  
  288. /* Exported functions: */
  289. #ifdef __STDC__
  290. void cl_run_program (mem_addr addr, int steps, int display);
  291. void cl_initialize_world (int run);
  292. void cycle_init (void);
  293. void mdu_and_fp_init (void);
  294. void print_pipeline (void);
  295. void print_pipeline_internal (char *buf);
  296. #else
  297. void cl_run_program ();
  298. void cl_initialize_world ();
  299. void cycle_init ();
  300. void mdu_and_fp_init ();
  301. void print_pipeline ();
  302. void print_pipeline_internal ();
  303. #endif
  304.  
  305.  
  306. /* Exported Variables: */
  307. extern int cycle_level, cycle_running, cycle_steps;
  308. extern int EX_bp_reg, MEM_bp_reg, CP_bp_reg, CP_bp_cc, CP_bp_z;
  309. extern reg_word EX_bp_val, MEM_bp_val, CP_bp_val;
  310. extern int FP_add_cnt, FP_mul_cnt, FP_div_cnt;
  311. extern PIPE_STAGE alu[], fpa[];
  312.  
  313.  
  314.  
  315.